package com.designpatterns;

import com.designpatterns.ProducerConsumer.Consumer;
import com.designpatterns.ProducerConsumer.Producer;
import com.designpatterns.ProducerConsumer.ProducerConsumerBridge;
import com.designpatterns.ProducerConsumer.ProducerConsumerBridgeNew;

import java.util.concurrent.*;

/**
 * Created by 41579 on 2017/5/25.
 */
public class main {
    public static void main(String[] args) {
//        MockFileInputSream mockFileInputSream = new MockFileInputSream();
//        mockFileInputSream.read();
//        MockBufferedInputStream mockBufferedInputStream = new MockBufferedInputStream(new MockFileInputSream());
//        mockBufferedInputStream.read();


//        RequestQueue requestQueue = new RequestQueue();
//        new Thread(new ClientThread(requestQueue)).start();
//        new Thread(new ServerThread(requestQueue)).start();
//        new Thread(new ServerThread(requestQueue)).start();

//        MyFilter1 myFilter1 = new MyFilter1();
//        MyFilter2 myFilter2 = new MyFilter2();
//        FilterChain filterChain = new ApplicationFilterChain();
//        filterChain.addFilter(myFilter1);
//        filterChain.addFilter(myFilter2);
//        filterChain.init();
//        filterChain.doFilter("1","2");

        ExecutorService service = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
                60L, TimeUnit.SECONDS,
                new SynchronousQueue<Runnable>());
        ProducerConsumerBridgeNew bridge = new ProducerConsumerBridgeNew();
        Consumer consumer1 = new Consumer(bridge);
        Consumer consumer2 = new Consumer(bridge);
        Consumer consumer3 = new Consumer(bridge);
        Producer producer1 = new Producer(bridge);
        Producer producer2 = new Producer(bridge);
        Producer producer3 = new Producer(bridge);
        new Thread(consumer1).start();
        new Thread(consumer2).start();
        new Thread(consumer3).start();
//        new Thread(producer1,"mkk").start();
        new Thread(producer2,"mkk2").start();
        new Thread(producer2,"mkk3").start();
        new Thread(producer2,"mkk4").start();
//        new Thread(producer3,"mkk3").start();

//        ReadWriteLock readWriteLock = new ReadWriteLock();
//        ReadThread rt1 = new ReadThread(readWriteLock);
//        ReadThread rt2 = new ReadThread(readWriteLock);
//        ReadThread rt3 = new ReadThread(readWriteLock);
//        WriteThread wt1 = new WriteThread(readWriteLock);
//        WriteThread wt2 = new WriteThread(readWriteLock);
//        WriteThread wt3 = new WriteThread(readWriteLock);
//        new Thread(rt1).start();
//        new Thread(rt2).start();
//        new Thread(rt3).start();
//        new Thread(wt1).start();
//        new Thread(wt2).start();
//        new Thread(wt3).start();

//        System.out.println(SimpleThreadLocal.getInstance());
//        System.out.println(SimpleThreadLocal.getInstance());
//        System.out.println(SimpleThreadLocal.getInstance());

//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                System.out.println(SimpleThreadLocal.getInstance());
//            }
//        }).start();
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                System.out.println(SimpleThreadLocal.getInstance());
//            }
//        }).start();
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                System.out.println(HungerThreadLocal.getInstance());
//            }
//        }).start();
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                System.out.println(HungerThreadLocal.getInstance());
//            }
//        }).start();

//        try {
//            Constructor[] c = Class.forName("SimpleThreadLocal").getDeclaredConstructors();
//            c[0].setAccessible(true);
//            System.out.println(c[0].newInstance());
//        } catch (Exception e){
//            e.printStackTrace();
//        }

    }
}
